#!/usr/bin/python2.4

# pylint: disable-msg=C6304

"""Manages time formatting."""

import time

FMT = '%Y-%m-%d %H%M'
XTIDE_FMT = '%Y %a %d %b %H%M'


def ScanTimeString(timestr):
  """Scans a date/time formatted per conventions used in this tool.

  Times are always written in PDT, of the format: 2011-05-11 1600

  TODO(rrh): allow for optional : in time

  Args:
    timestr: A string to scan.

  Returns:
    The number of seconds since the Unix epoch.
  """
  timeblob = time.strptime(timestr, FMT)
  return time.mktime(timeblob)


def ScanXtideTimeString(timestr):
  timeblob = time.strptime(timestr, XTIDE_FMT)
  return time.mktime(timeblob)


def FormatTime(epoch_time_secs):
  return time.strftime(FMT, time.localtime(epoch_time_secs))
